<?php
namespace App\Services;
use Illuminate\Support\Facades\Storage;
class ImageClass
{
	function base64toimg($imgbase)
	{
		$base64_str = substr($imgbase, strpos($imgbase, ",")+1);
        $image=base64_decode($base64_str);
        $imgname=rand(1000,10000).time().'.png';
        $path = 'images/'.date('Ymd').'/'.$imgname;
        Storage::put($path,$image);
        return '/storage/'.$path;
	}

	//$lng 经度
	//$lat 维度
	function maptoimg($lng,$lat,$name)
	{
		$bdak = '9DbR7Ge0vRY3qtiPeVStVve3';
		$gdak = '4cba5031276db6a671290687e176a350';
		$baiduUrl = 'http://api.map.baidu.com/staticimage/v2?ak='.$bdak
			.'&mcode=666666&center='
			.$lng.','
			.$lat.'&width=500&height=300&zoom=13&markers=定位|'
			.$lng.','
			.$lat.'&markerStyles=l,A,0xff0000';
		$name = mb_substr($name,0,15);
		$gdUrl = 'https://restapi.amap.com/v3/staticmap?location='
			.$lng.','
			.$lat
			.'&zoom=13&size=600*400&labels='.$name.',2,0,16,0x000000,0xFFFFFF:'.$lng.','.$lat.'&markers=mid,,A:'
			.$lng.','.$lat.'&key='.$gdak;
		$image = file_get_contents($gdUrl);
		$imgname=rand(1000,10000).time().'.png';
		$path = 'images/'.date('Ymd').'/'.$imgname;
        Storage::put($path,$image);
		Storage::disk('public')->put($imgname,$image);
		return '/storage/'.$path;
	}
}
	